package cn.platform.controller;

import cn.platform.entity.StuRecord;
import cn.platform.request.StuRecord.StuRecordQueryDTO;
import cn.platform.request.StuRecord.StuRecordUpdateDTO;
import cn.platform.response.PageResult;
import cn.platform.response.Result;
import cn.platform.response.StuRecordVO;
import cn.platform.service.StuRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/comment") // 评语相关接口路径
public class CommentController {
    @Autowired
    private StuRecordService stuRecordService;

    // 新增：获取学生列表接口
    @GetMapping("/student")
    public Result getStudents(@RequestParam(required = false) String name) {
        return Result.success(stuRecordService.getStudents(name));
    }

    // 新增：获取老师列表接口
    @GetMapping("/teacher")
    public Result getTeachers(@RequestParam(required = false) String name) {
        return Result.success(stuRecordService.getTeachers(name));
    }


    @GetMapping
    public Result page(StuRecordQueryDTO queryDTO) {
        log.info("分页查询学生评语");
        queryDTO.setType("评语");
        PageResult<StuRecordVO> pageResult = stuRecordService.page(queryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/{id}")
    public Result detail(@PathVariable Integer id) {
        log.info("查看学生评语详情");
        StuRecordVO stuRecordVO = stuRecordService.detail(id);
        return Result.success(stuRecordVO);
    }

    @PostMapping
    public Result save(@RequestBody StuRecord stuRecord) {
        log.info("新增学生评语");
        stuRecord.setType("评语");
        stuRecordService.save(stuRecord);
        return Result.success();
    }


@PutMapping("/{id}")
public Result update(@PathVariable String id, @RequestBody StuRecordUpdateDTO stuRecordUpdateDTO) {
    log.info("更新学生评价 ID {}: {}", id, stuRecordUpdateDTO);
    stuRecordUpdateDTO.setId(id);
    stuRecordService.update(stuRecordUpdateDTO);
    return Result.success();
}


    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除学生评语，ID: {}", id);
        stuRecordService.delete(id);
        return Result.success();
    }

    @PostMapping("/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        log.info("批量删除学生评语，ID列表: {}", ids);
        stuRecordService.deleteBatch(ids);
        return Result.success();
    }
}
